<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

    </style>
</head>

<body>
    <div id="ListObj">
        <h2>添加列表数据：</h2>
        <input type="text" v-model="newObj" @keyup.enter="addObj">
        <button @click="addObj">添加</button>

        <ul>
            <li v-for="(e,i) in newArr" :key="e">
                {{i+1}}&nbsp;&nbsp;{{e}}
                 <button @click="del(i)">X</button><!--del(e) -->
            </li>
        </ul>
    </div>
    <script src="js/vue.js"></script>
    <script>
        let List = new Vue({
            el: "#ListObj",
            data: {
                newObj: "",
                newArr: []
            },
            methods: {
                addObj() {
                    if (this.newObj == '') {
                        return
                    } else {
                        console.log(this.newObj);
                        this.newArr.push(this.newObj);
                        this.newObj = "";
                    }
                },
                del(v) {
                    console.log(222)
                    // this.newArr = this.newArr.filter(e=>{
                    //     return e != v;
                    // })
                    //删除记录 &&操作的熔断机制，当前面的为true时，才执行下个语句
                    confirm('确定删除语句吗？') && this.newArr.splice(v, 1);
                }
            }
        })
    </script>
</body>

</html>